import React from 'react';
import { useNavigate } from 'react-router-dom';
import {store} from '../store/index'
import {joinCart} from '../store/slice/cart'


function GoodsList(props) {
    const navigate = useNavigate()
    return (
        <div>
            {
                store.getState().goods.goodsList.map(item=>{
                    return (
                        <div key={item.id}>
                            <p>商品名称：{item.goodsName}</p>
                            <p>商品价格：￥{item.goodsPrice.toFixed(2)}</p>
                            <button onClick={()=>{
                                store.dispatch(joinCart(item))
                                navigate('/cartList')
                            }} >加入购物车</button>
                        </div>
                    )
                })
            }
        
        </div>
    );
}

export default GoodsList;